﻿@model IEnumerable<ServiceLayer.TagServices.TagListDto>

@{
    ViewBag.Title = "Tags";
}

<h2>Tags</h2>

@if (TempData["message"] != null)
{
    <div class="text-success">@TempData["message"]</div><br />
}
@if (TempData["errorMessage"] != null)
{
    <div class="text-danger"><strong>@TempData["errorMessage"]</strong></div>
}

<p>
    This is a demonstration of <a href="https://github.com/JonPSmith/GenericServices" target="_blank">GenericServices'</a>
    database CRUD (Create, Read, Update/Edit and Delete) services done synchronously, i.e no wait states to improve web site capacity.
    (See @Html.ActionLink("Tags Async", "Index", "TagsAsync") for async versions of the same commands).
</p>
<p>
    Below you will see a table of Tags which can be manipulated. Tags are really simple so we use the direct GenericServices rather than 
    the DTO GenericServices used for Posts. 
</p>
<p>
    However we do use a simple dto in the list to show how many posts use the tag. Also note that a validation check is done 
    inside the EF SaveChanges methed to ensure that the slug is unique.
</p>
<hr />
<div>
    <span>@Html.ActionLink("Create New Tag", "Create") | @Html.ActionLink("Posts Page", "Index", "Posts") | @Html.ActionLink("Blogs Page", "Index", "Blogs")</span>
    <span class="pull-right"><strong>@Html.ActionLink("Explanation of the code", "CodeView")</strong></span>
</div>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Slug)
        </th>
        <th>
            Num Posts Used In
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Slug)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.PostsCount)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.TagId }) |
            @Html.ActionLink("Details", "Details", new { id=item.TagId }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.TagId })
        </td>
    </tr>
}

</table>
